import { MessageStyle, useMessage } from "@/hooks/message";
import { AxiosError } from "axios";
import axios from "axios";
import { zError } from "../console";

export function catchException(reason: any) {
  // won't prompt if canceled by user
  if (axios.isCancel(reason)) return;

  const { zTip } = useMessage();

  zError(reason);
  if (reason instanceof AxiosError) {
    zTip(reason.message, MessageStyle.dialog, "error");
  } else {
    zTip(reason, MessageStyle.dialog, "error");
  }
}
